﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace PFAGame
{
    class ProjectileQueen : AProjectile
    {
        Texture2D tmpTex;
        float angle;
        public AObject Target;
        public Vector2 velocity = new Vector2();

        public override void init()
        {
            obj = AObject.e_object.PROJECTILEQUEEN;
            tmpTex = ScreenManager.Singleton.Game.Content.Load<Texture2D>("Fireball");

            lifeTime = 20;
        }

        public override void update(GameTime gameTime)
        {
            // deplacement dans AProjectile
            //base.update(gameTime);

            lifeTime -= (float)gameTime.ElapsedGameTime.Ticks / 10000000;
            if (lifeTime < 0)
                GameplayScreen.Singleton.DeleteProjectileList.Add(this);

            direction = (Target.Position - position);
            direction.Normalize();
            velocity += direction * Speed * (float)gameTime.ElapsedGameTime.Ticks / 10000000;
            position += velocity * (float)gameTime.ElapsedGameTime.Ticks / 10000000;

            angle = (float)Math.Acos(direction.X);
            if (direction.Y < 0)
                angle = -angle;

            // SphereCast pour tester les collision sur la liste de mob (projectile de joueur)
            List<AObject> list = AObject.SphereCast(position + orientation * 0.25f, 0.25f, GameplayScreen.Singleton.Players);
            if (list.Count != 0)
            {
                // si un objet est touché, on applique les dégats et on détruit le projectile
                foreach (APlayer player in list)
                    player.receiveDammage(Dammage);
                GameplayScreen.Singleton.DeleteProjectileList.Add(this);
            }

        }

        public override void draw(GameTime gameTime, Camera camera)
        {
            base.draw(gameTime, camera);
            displayRectangle.X += camera.ZoomLevel / 2;
            displayRectangle.Y += camera.ZoomLevel / 2;
            ScreenManager.Singleton.SpriteBatch.Draw(tmpTex, displayRectangle, new Rectangle(0, 0, 100, 81), Color.Blue, angle, new Vector2(50, 40), SpriteEffects.None, 0);
        }
    }
}
